package com.zchat.android.service_aidl_beans;

import com.zchat.api.ZChat;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * 测试Bean
 * 建立bean对应的表结构
 * @author Oliverzhu
 *	2012/6/12
 */
public class TestBean implements Parcelable{
	private int id;
	
	private String name;
	
	public static final String TABLE_NAME = "testbean";
	
	private static final String TESTBEANID = "testbeanid";
	private static final String TESTBEANNAME = "testbeanname";
	public static final String SQL_DROP = "DROP TABLE IF EXISTS " + TABLE_NAME;
	
	public static final Uri CONTENT_URI=
			 Uri.parse("content://"+ ZChat.AUTHORITY+ "/" + TABLE_NAME);

	
	/**
	 * 建表
	 */
	public static final String SQL_CREATE = 
			"CREATE TABLE "+ TABLE_NAME 
			+ "(_ID INTEGER PRIMARY KEY AUTOINCREMENT," 
			+ TESTBEANID + " INTEGER, " 
			+ TESTBEANNAME + " VARCHAR(10))";
	
	/** 插入数据 */
	public static final String SQL_INSERT = 
			"INSERT INTO " + TABLE_NAME 
			+ " ("+ TESTBEANID + "," 
			+ TESTBEANNAME + ")"
			+ " VALUES (#,'#')";
	
	/** 查询数据 */
	public static final String SQL_QUERY = 
			"SELECT * FROM " + TABLE_NAME
			+ " WHERE " + TESTBEANID + "=# ";
	
	
	public static final Parcelable.Creator<TestBean> CREATOR = 
			new Creator<TestBean>() {
				
				@Override
				public TestBean[] newArray(int size) {
					return new TestBean[size];
				}
				
				@Override
				public TestBean createFromParcel(Parcel source) {
					return new TestBean(source);
				}
			};
			
	public TestBean()
	{
		
	}
	
	/**
	 * 复杂对象采用如下处理方式
	 * Plate plate = (Plate) in.readValue(Plate.class.getClassLoader());
	 *	List<Subject> subjects = (List<Subject>) in.readValue(Subject.class.getClassLoader());
	 * @param in
	 */
	public TestBean(Parcel in)
	{
		id = in.readInt();
		name = in.readString();
//		
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(id);
		dest.writeString(name);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
